//
//  Main3ViewController.m
//  HaierGMS_APP
//
//  Created by 堂堂 on 16/11/25.
//  Copyright © 2016年 堂堂. All rights reserved.
//

#import "Main3ViewController.h"
#import "DateModel.h"
#import "DateUtils.h"
#import "UIColor+Hex.h"
#import "MBProgressHUD+MJ.h"
#import "UserDefaultUtil.h"
#import "HttpReauestParam.h"
#import "AFHTTPRequestOperationManager.h"
#import "NoticeViewController.h"
#import "NoticeDetailViewController.h"
#import "OrderDetailViewController.h"

#define ScreenHeight [[UIScreen mainScreen] bounds].size.height//获取屏幕高度，兼容性测试
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width//获取屏幕宽度，兼容性测试
@interface Main3ViewController ()

@property NSMutableArray *data;
@property NSArray *orderData;

@property NSArray *viewArray;
@property UILabel *date_lab;
@property int year;
@property int month;

@property int top_height;
@property UIScrollView *scrollView;

@property int choosePos;
@end

@implementation Main3ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _data = [[NSMutableArray alloc]init];
    _year = [DateUtils getYear];
    _month = [[DateUtils getMonth] integerValue];
    
    
    
    [self initView];
    [self getTheData];
    [self upDateView];
    
    [self getData:[DateUtils getDate]];
    
    [self getNumData:[DateUtils getFirstDay:_year month:_month] endDate:[DateUtils getEndDay:_year month:_month]];
}


-(void)initView{
    
    
    _topView.image = [UIImage imageNamed:@"main3_top_view"];
    _topView.contentMode = UIViewContentModeCenter;
    int height = 0;
    
    //左边
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, height, 80, 45)];
    [leftBtn setImage:[UIImage imageNamed:@"main3_left"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(lastClick) forControlEvents:UIControlEventTouchUpInside];
    [_contentView addSubview:leftBtn];
    //右边
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 80, height, 80, 45)];
    [rightBtn addTarget:self action:@selector(nextClick) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setImage:[UIImage imageNamed:@"main3_right"] forState:UIControlStateNormal];
    [_contentView addSubview:rightBtn];
    //日期
    _date_lab = [[UILabel alloc]initWithFrame:CGRectMake(80, height, ScreenWidth - 160, 45)];
    _date_lab.font = [UIFont systemFontOfSize:15];
    _date_lab.text = [NSString stringWithFormat:@"%i年%i月",_year,_month];
    _date_lab.textAlignment = NSTextAlignmentCenter;
    [_contentView addSubview:_date_lab];
    
    height = height + 45;
    int week_widget = ScreenWidth / 7;
    NSArray *week = @[@"日",@"一",@"二",@"三",@"四",@"五",@"六"];
    for (int i = 0; i < week.count; i++) {
        UILabel *week_lab = [[UILabel alloc]initWithFrame:CGRectMake(i * week_widget, height, week_widget, 45)];
        week_lab.text = week[i];
        week_lab.font = [UIFont systemFontOfSize:14];
        week_lab.textAlignment = NSTextAlignmentCenter;
        [_contentView addSubview:week_lab];
    }
    height = height + 45;
    for (int i = 1; i < 36; i++) {
        
        UIButton *week_lab = [[UIButton alloc]initWithFrame:CGRectMake(((i - 1) % 7) * week_widget, height, week_widget, 40)];
        week_lab.tag = i;
        week_lab.font = [UIFont systemFontOfSize:13];
        [week_lab addTarget:self action:@selector(dateClick:) forControlEvents:UIControlEventTouchUpInside];
        [week_lab setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(((i - 1) % 7) * week_widget, height + 10, week_widget, 20)];
        
        image.contentMode = UIViewContentModeCenter;
        image.tag = i + 100;
        [_contentView addSubview:image];
        [_contentView addSubview:week_lab];
        if(i % 7 == 0){
            height = height + 40;
        }
        
    }
    NSString *appoin =@"待预约";
    CGSize size = [appoin sizeWithFont:[UIFont systemFontOfSize:13]];
    //预约
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(week_widget, height + 5, 10, 10)];
    UILabel *lab1 = [[UILabel alloc]initWithFrame:CGRectMake(week_widget + 20, height, size.width, 20)];
    lab1.text = @"待预约";
    lab1.textAlignment = NSTextAlignmentCenter;
    lab1.font = [UIFont systemFontOfSize:13];
    view1.backgroundColor = [UIColor colorWithHexString:@"#c7003a"];
    [_contentView addSubview:view1];
    [_contentView addSubview:lab1];
    //提货
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(week_widget * 3, height + 5, 10, 10)];
    UILabel *lab2 = [[UILabel alloc]initWithFrame:CGRectMake(week_widget * 3 + 20, height, size.width, 20)];
    lab2.text = @"待提货";
    lab2.font = [UIFont systemFontOfSize:13];
    lab2.textAlignment = NSTextAlignmentCenter;
    view2.backgroundColor = [UIColor colorWithHexString:@"#5bc0de"];
    [_contentView addSubview:view2];
    [_contentView addSubview:lab2];
    //提货
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(week_widget * 5, height + 5, 10, 10)];
    UILabel *lab3 = [[UILabel alloc]initWithFrame:CGRectMake(week_widget * 5 + 20, height, size.width, 20)];
    lab3.text = @"待签收";
    lab3.font = [UIFont systemFontOfSize:13];
    lab3.textAlignment = NSTextAlignmentCenter;
    view3.backgroundColor = [UIColor colorWithHexString:@"#00d11c"];
    [_contentView addSubview:view3];
    [_contentView addSubview:lab3];
    height = height + 30;
    _top_height = height;
    
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, _top_height, ScreenWidth, _contentView.frame.size.height - _top_height)];
    
    [_contentView addSubview:_scrollView];
}
-(void)getTheData{
    _data = [[NSMutableArray alloc]init];
    int day = [DateUtils dayOfMonth:[NSString stringWithFormat:@"%i-%i",_year,_month]];
    int week = [DateUtils getWeek:[NSString stringWithFormat:@"%i-%i-01",_year,_month]];
    
    NSLog(@"day=%i",day);
    NSLog(@"week=%i",week);
    for (int i = 0 ; i < week - 1; i++) {
        DateModel *d = [[DateModel alloc]init];
        d.isEmp = YES;
        [_data addObject:d];
    }
    NSString *nowDay = [DateUtils getDate];
    
    NSString *myMonth = [NSString stringWithFormat:@"%i",_month];
    if (_month < 10) {
        myMonth = [NSString stringWithFormat:@"0%i",_month];
    }
    for (int i = 1 ; i <= day; i++) {
        DateModel *d = [[DateModel alloc]init];
        d.showDate = i;
        if (i < 10) {
            d.date = [NSString stringWithFormat:@"%i-%@-0%i",_year,myMonth,i];
        }else{
            d.date = [NSString stringWithFormat:@"%i-%@-%i",_year,myMonth,i];
        }

        d.isNowDay = [d.date isEqualToString:nowDay];
        
        [_data addObject:d];
    }
}

-(void)upDateView{
    
    for (int i = 0; i < 35; i++) {
        UIButton *lab = [self.view viewWithTag:i + 1];
        UIImageView *image = [self.view viewWithTag:i + 101];
        if (i< _data.count) {
            DateModel *d = _data[i];
            
            if (!d.isEmp) {
                
                [lab setTitle:[NSString stringWithFormat:@"%i",d.showDate] forState:UIControlStateNormal];
                if (d.isNowDay) {
                    [lab setTitleColor:[UIColor colorWithHexString:@"#ff7e00"] forState:UIControlStateNormal];
                }else{
                    [lab setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                }
                
                if (d.appointment && d.pickup && d.sign) {
                    image.image = [UIImage imageNamed:@"all_image"];
                }else if (d.appointment && d.pickup && !d.sign) {
                    image.image = [UIImage imageNamed:@"honglan_image"];
                }else if (d.appointment && !d.pickup && d.sign) {
                    image.image = [UIImage imageNamed:@"honglv_image"];
                }else if (d.appointment && !d.pickup && !d.sign) {
                    image.image = [UIImage imageNamed:@"hong_image"];
                }else if (!d.appointment && d.pickup && d.sign) {
                    image.image = [UIImage imageNamed:@"lanlv_image"];
                }else if (!d.appointment && d.pickup && !d.sign) {
                    image.image = [UIImage imageNamed:@"lan_image"];
                }else if (!d.appointment && !d.pickup && d.sign) {
                    image.image = [UIImage imageNamed:@"lv_image"];
                }else if (!d.appointment && !d.pickup && !d.sign) {
                    image.image = nil;
                }
                
            }else{
                [lab setTitle:@"" forState:UIControlStateNormal];
                image.image = nil;
            }
        }else{
            [lab setTitle:@"" forState:UIControlStateNormal];
            image.image = nil;
        }
        
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)nextClick{
    NSArray *array = [DateUtils getNextMonth:_year month:_month];
    _year = [array[0] integerValue];
    _month = [array[1] integerValue];
    
    _date_lab.text = [NSString stringWithFormat:@"%i年%i月",_year,_month];
    
    [self getTheData];
    [self upDateView];
    [self getNumData:[DateUtils getFirstDay:_year month:_month] endDate:[DateUtils getEndDay:_year month:_month]];
}
-(void)lastClick{
    NSArray *array = [DateUtils getLastMonth:_year month:_month];
    _year = [array[0] integerValue];
    _month = [array[1] integerValue];
    
    _date_lab.text = [NSString stringWithFormat:@"%i年%i月",_year,_month];
    
    [self getTheData];
    [self upDateView];
    [self getNumData:[DateUtils getFirstDay:_year month:_month] endDate:[DateUtils getEndDay:_year month:_month]];

}

-(void)dateClick:(UIButton *)btn{
    int tag = btn.tag;
    _choosePos = tag;
    [self upDateView];
    
    UIImageView *img = [self.view viewWithTag:100 + tag];
    img.image = [UIImage imageNamed:@"main3_bg_image"];
    
    DateModel *d = _data[tag - 1];
    [self getData:d.date];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void) getData:(NSString *) date{

    NSString *startDate = date;
    NSString *endDate = date;
    NSString *userId =[UserDefaultUtil getUserId];
    NSDictionary * dic = @{@"identifier": userId ,@"page":[NSString stringWithFormat:@"%i",1],@"size":[NSString stringWithFormat:@"%i",20],@"startDate":startDate,@"endDate":endDate,@"query":@"",@"orderType":@"",@"status":@"201,301,401"};
    
    NSLog(@"%@",dic);
    
    HttpReauestParam * param = [[HttpReauestParam alloc]initWithData:@"order_list_get" content:[self dictionaryToJson:dic] urlType:0];
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    // [MBProgressHUD showMessage:@"获取订单"];
    [manage POST:param.SEVICE_URL parameters:param.param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary * data = [NSJSONSerialization JSONObjectWithData:operation.responseObject options:0 error:nil];
        
        
        if ([data[@"success"] boolValue]) {
            
            NSString *content = data[@"result"];
            
            NSLog(@"%@",content);
            _orderData = [NSJSONSerialization JSONObjectWithData:[content dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
            
            [self setOrderView:_orderData];
            
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    }];
}
-(NSString*)dictionaryToJson:(NSDictionary *)dic

{
    
    NSError *parseError = nil;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
}

-(void)setOrderView:(NSArray *)orderData{
    
    UIView *contentView = [self.view viewWithTag:1001];
    if (contentView != nil) {
        [contentView removeFromSuperview];
    }
    contentView = [[UIView alloc]init];
    contentView.tag = 1001;
    
    int _msg_height = 10;
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0,_msg_height , ScreenWidth, 1)];
    line.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
    [contentView addSubview:line];
    
    for (int i = 0; i < orderData.count; i++) {
        NSDictionary *dic = orderData[i];
        
        UIControl *control2 = [[UIControl alloc]initWithFrame:CGRectMake(0, _msg_height, ScreenWidth, 148)];
        control2.tag = i + 10000;
        [control2 addTarget:self action:@selector(order_click2:) forControlEvents:UIControlEventTouchUpInside];
        //[control2 sendActionsForControlEvents:UIControlEventTouchUpInside];
        
        
        control2.backgroundColor = [UIColor whiteColor];
        
        [contentView addSubview:control2];
        
        //来源图片
        UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, _msg_height, 18, 32)];
        image1.contentMode = UIViewContentModeCenter;
        if ([dic[@"orderFrom"] isEqualToString:@"天猫"] || [dic[@"orderFrom"] isEqualToString:@"4PL-天猫"]) {
            image1.image = [UIImage imageNamed:@"grab_order_tm"];
        }
        if ([dic[@"orderFrom"] isEqualToString:@"极有家"]) {
            image1.image = [UIImage imageNamed:@"grab_order_jyj"];
        }
        if ([dic[@"orderFrom"] isEqualToString:@"其它"]) {
            image1.image = [UIImage imageNamed:@"grab_order_qt"];
        }
        [contentView addSubview:image1];
        //单号
        NSString *serviceNo = [NSString stringWithFormat:@"%@(%@)",dic[@"serviceNo"],dic[@"serviceStatus"]];
        CGSize size = [serviceNo sizeWithFont:[UIFont systemFontOfSize:13]];
        UILabel *lab_orderNo = [[UILabel alloc]initWithFrame:CGRectMake(30, _msg_height, size.width, 32)];
        lab_orderNo.font = [UIFont systemFontOfSize:13];
        lab_orderNo.text = serviceNo;
        [contentView addSubview:lab_orderNo];
        //日期
        NSDateFormatter *sf = [[NSDateFormatter alloc]init];
        [sf setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        
        NSDateFormatter *sf2 = [[NSDateFormatter alloc]init];
        [sf2 setDateFormat:@"yyyy-MM-dd"];
        NSDate * date1 = [sf dateFromString:dic[@"serviceDate"]];
        
        
        
        NSString *date = [sf2 stringFromDate:date1];
        size = [date sizeWithFont:[UIFont systemFontOfSize:13]];
        UILabel *lab_orderDate = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth - 10 - size.width - 3 , _msg_height + 5 , size.width + 3, 22)];
        lab_orderDate.font = [UIFont systemFontOfSize:10];
        lab_orderDate.text = date;
        lab_orderDate.textAlignment = NSTextAlignmentCenter;
        if(dic[@"appointmentTime"] != nil && ![dic[@"appointmentTime"] isEqualToString:@""]){
            NSDate * date2 = [sf dateFromString:dic[@"appointmentTime"]];
            if(date2.timeIntervalSince1970 - [NSDate date].timeIntervalSince1970 < 2* 60 * 60){
                [lab_orderDate.layer setBorderWidth:1];
                [lab_orderDate.layer setBorderColor:[UIColor colorWithHexString:@"ff7e00"].CGColor];
                lab_orderDate.textColor = [UIColor colorWithHexString:@"ff7e00"];
                lab_orderDate.layer.cornerRadius = 11 ;
                
                lab_orderDate.layer.masksToBounds = YES;
            }
        }
        [contentView addSubview:lab_orderDate];
        _msg_height = _msg_height + 32;
        //
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(0,_msg_height , ScreenWidth, 1)];
        line1.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
        [contentView addSubview:line1];
        _msg_height = _msg_height + 1;
        //客户信息
        UIImageView *image2 = [[UIImageView alloc]initWithFrame:CGRectMake(10, _msg_height, 18, 32)];
        image2.contentMode = UIViewContentModeCenter;
        image2.image = [UIImage imageNamed:@"grab_order_user"];
        [contentView addSubview:image2];
        //名字电话
        NSString *serviceUser= [NSString stringWithFormat:@"%@(%@)",dic[@"userName"],dic[@"userPhone"]];
        size = [serviceUser sizeWithFont:[UIFont systemFontOfSize:13]];
        UILabel *lab_user = [[UILabel alloc]initWithFrame:CGRectMake(28, _msg_height, size.width, 32)];
        lab_user.font = [UIFont systemFontOfSize:13];
        lab_user.text = serviceUser;
        [contentView addSubview:lab_user];
        //类型
        NSString *serviceType= [NSString stringWithFormat:@"%@",dic[@"serviceType"]];
        size = [serviceType sizeWithFont:[UIFont systemFontOfSize:13]];
        UILabel *lab_type = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth - 10 - size.width, _msg_height, size.width, 32)];
        lab_type.font = [UIFont systemFontOfSize:13];
        lab_type.text = serviceType;
        [contentView addSubview:lab_type];
        
        UIImageView *image3 = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth - 28 - size.width, _msg_height, 18, 32)];
        image3.contentMode = UIViewContentModeCenter;
        image3.image = [UIImage imageNamed:@"grab_order_type"];
        [contentView addSubview:image3];
        
        _msg_height = _msg_height + 32;
        //提货地址
        UIImageView *image4 = [[UIImageView alloc]initWithFrame:CGRectMake(10, _msg_height, 18, 40)];
        image4.contentMode = UIViewContentModeCenter;
        image4.image = [UIImage imageNamed:@"grab_order_address"];
        [contentView addSubview:image4];
        
        NSString *servicePickup= [NSString stringWithFormat:@"%@",dic[@"pickupAddress"]];
        size = [servicePickup sizeWithFont:[UIFont systemFontOfSize:13]];
        UILabel *lab_pick_up = [[UILabel alloc]initWithFrame:CGRectMake(28, _msg_height, size.width, 40)];
        lab_pick_up.font = [UIFont systemFontOfSize:13];
        lab_pick_up.text = servicePickup;
        lab_pick_up.numberOfLines = 2;
        lab_pick_up.lineBreakMode = NSLineBreakByTruncatingTail;
        CGSize maximumLabelSize = CGSizeMake(100, 9999);//labelsize的最大值
        //关键语句
        CGSize expectSize = [lab_pick_up sizeThatFits:maximumLabelSize];
        // lab_pick_up.frame =CGRectMake(28, _msg_height, size.width, expectSize.height);
        [contentView addSubview:lab_pick_up];
        
        _msg_height = _msg_height + 40;
        //客户地址
        UIImageView *image5 = [[UIImageView alloc]initWithFrame:CGRectMake(10, _msg_height, 18, 40)];
        image5.contentMode = UIViewContentModeCenter;
        image5.image = [UIImage imageNamed:@"grab_order_address"];
        [contentView addSubview:image5];
        
        NSString *serviceUserAddress = [NSString stringWithFormat:@"%@",dic[@"userAddress"]];
        size = [serviceUserAddress sizeWithFont:[UIFont systemFontOfSize:13]];
        UILabel *lab_user_address = [[UILabel alloc]initWithFrame:CGRectMake(28, _msg_height, size.width, 40)];
        lab_user_address.font = [UIFont systemFontOfSize:13];
        lab_user_address.text = serviceUserAddress;
        [contentView addSubview:lab_user_address];
        
        _msg_height = _msg_height + 40;
        
        UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(0,_msg_height , ScreenWidth, 5)];
        line3.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
        [contentView addSubview:line3];
        _msg_height = _msg_height + 5;
        
        
        
    }
    contentView.frame = CGRectMake(0, 0, ScreenWidth, _msg_height + 20);
    _scrollView.frame = CGRectMake(0, _top_height, ScreenWidth, _contentView.frame.size.height - _top_height);
    [_scrollView addSubview:contentView];
    _scrollView.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
    _scrollView.contentSize = CGSizeMake(ScreenWidth, 60 + _msg_height);
}

-(void)order_click2:(UIView *)view{
    NSLog(@"order_click2");
    NSDictionary *dic = _orderData[view.tag - 10000];
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
    
    
    OrderDetailViewController *order = [story instantiateViewControllerWithIdentifier:@"order_detail"];
    order.serviceNo = dic[@"serviceNo"];
    [self.navigationController pushViewController:order animated:YES];
}
- (IBAction)msg_show:(id)sender{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
    NoticeViewController *vc = [sb instantiateViewControllerWithIdentifier:@"notice_view"];
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)code_click:(id)sender {
    
    NSLog(@"启动二维码");
    
    static QRCodeReaderViewController *reader = nil;
    static dispatch_once_t onceToken;
    
    
    dispatch_once(&onceToken, ^{
        reader                        = [QRCodeReaderViewController new];
        reader.modalPresentationStyle = UIModalPresentationFormSheet;
    });
    reader.delegate = self;
    
    [reader setCompletionWithBlock:^(NSString *resultAsString) {
        
    }];
    
    [self presentViewController:reader animated:YES completion:NULL];
}
//二维码回调
- (void)reader:(QRCodeReaderViewController *)reader didScanResult:(NSString *)result{
    
    NSLog(@"%@",result);
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    NSError *error;
    NSDictionary * data = [NSJSONSerialization JSONObjectWithData:[result dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error];
    if (data != nil) {
        [self getServiceNo:data[@"serviceNo"]];
    }else{
        [MBProgressHUD showError:@"数据格式不正确"];
    }
    
}

- (void)readerDidCancel:(QRCodeReaderViewController *)reader{
    NSLog(@"readerDidCancel被执行了");
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

-(void)getServiceNo:(NSString *)serviceNo{
    NSDateFormatter *sf = [[NSDateFormatter alloc]init];
    [sf setDateFormat:@"yyyy-MM-dd"];
    NSString *startDate = @"2016-01-01";
    NSString *endDate = [sf stringFromDate:[NSDate date]];
    
    NSString *userId =[UserDefaultUtil getUserId];
    NSDictionary * dic = @{@"identifier": userId ,@"page":@"1",@"size":[NSString stringWithFormat:@"%i",20],@"startDate":startDate,@"endDate":endDate,@"query":serviceNo,@"orderType":@"",@"status":@"201,401,301,901,501,601,610,701"};
    
    NSLog(@"%@",dic);
    
    HttpReauestParam * param = [[HttpReauestParam alloc]initWithData:@"order_list_get" content:[self dictionaryToJson:dic] urlType:0];
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    // [MBProgressHUD showMessage:@"获取订单"];
    [manage POST:param.SEVICE_URL parameters:param.param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary * data = [NSJSONSerialization JSONObjectWithData:operation.responseObject options:0 error:nil];
        
        
        if ([data[@"success"] boolValue]) {
            NSString *content = data[@"result"];
            
            NSLog(@"%@",content);
            NSArray *array = [NSJSONSerialization JSONObjectWithData:[content dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
            if (array.count > 0) {
                
                UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
                
                
                OrderDetailViewController *order = [story instantiateViewControllerWithIdentifier:@"order_detail"];
                order.serviceNo = serviceNo;
                [self.navigationController pushViewController:order animated:YES];
            }else{
                [MBProgressHUD showError:@"无该订单信息"];
            }
        }else{
            [MBProgressHUD showError:data[@"errorMsg"]];
        }
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:@"网络连接失败"];
    }];
}

-(void) getNumData:(NSString *) startDate endDate:(NSString *)endDate{
    

    NSString *userId =[UserDefaultUtil getUserId];
    NSDictionary * dic = @{@"identifier": userId ,@"startDate":startDate,@"endDate":endDate};
    
    NSLog(@"%@",dic);
    
    HttpReauestParam * param = [[HttpReauestParam alloc]initWithData:@"calendar_record" content:[self dictionaryToJson:dic] urlType:0];
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    // [MBProgressHUD showMessage:@"获取订单"];
    [manage POST:param.SEVICE_URL parameters:param.param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary * data = [NSJSONSerialization JSONObjectWithData:operation.responseObject options:0 error:nil];
        
        
        if ([data[@"success"] boolValue]) {
            
            NSArray *content = data[@"result"];
            
            for (int i = 0; i < content.count; i++) {
                NSDictionary *dic = content[i];
                
                
                for (int j = 0; j < _data.count; j++) {
                    DateModel *d = _data[j];
                    
                    if ([d.date isEqualToString:dic[@"date"]]) {
                         d.appointment = [dic[@"appointmentNum"] integerValue] > 0;
                         d.pickup = [dic[@"pickupNum"] integerValue] > 0;
                         d.sign = [dic[@"signNum"] integerValue] > 0;
                    }
                }
            }
            
            [self upDateView];
            
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    }];
}
@end
